/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: javase202202 - Arr5
 * <p>Powered by Lisi On 2022-06-02 17:56:28
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class Arr5 {
    public static void main(String[] args) {
        var rand = new Random();
        var nums = new int[10];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = rand.nextInt(100) + 1;
        }
        System.out.printf("排序前：%s%n", Arrays.toString(nums));

        //使用升序排序，
        //Arrays.sort(nums);

        //冒泡排序
        boolean f = rand.nextBoolean();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (f) {
                    if (nums[j] < nums[j + 1]) {
                        int t = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = t;
                    }
                } else {
                    if (nums[j] > nums[j + 1]) {
                        int t = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = t;
                    }
                }
            }
        }
        System.out.printf("排序后(%s)：%s%n", f ? "降序" : "升序", Arrays.toString(nums));
    }
}
